package com.weeasy.qrcode.controller;

import com.weeasy.core.common.Result;
import com.weeasy.qrcode.service.QRCodeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 微信二维码控制器
 * 
 * @author we-easy
 * @since 1.0.0
 */
@RestController
@RequestMapping("/qrcode")
@RequiredArgsConstructor
@CrossOrigin(origins = "*")
public class QRCodeController {

    private final QRCodeService qrCodeService;

    /**
     * 生成二维码
     * 
     * @param content 二维码内容
     * @param size 二维码大小
     * @return 二维码信息
     */
    @PostMapping("/generate")
    public Result<String> generateQRCode(@RequestParam String content, 
                                       @RequestParam(defaultValue = "200") Integer size) {
        String result = qrCodeService.generateQRCode(content, size);
        return Result.success("生成二维码成功", result);
    }

    /**
     * 扫描二维码
     * 
     * @param qrCodeData 二维码数据
     * @return 扫描结果
     */
    @PostMapping("/scan")
    public Result<String> scanQRCode(@RequestParam String qrCodeData) {
        String result = qrCodeService.scanQRCode(qrCodeData);
        return Result.success("扫描二维码成功", result);
    }
}
